//
//  ServiceUserNew.m
//  suRead
//
//  Created by colin on 2020/1/3.
//  Copyright © 2020 bao. All rights reserved.
//

#import "ServiceUserNew.h"
#import "ServiceUtils.h"
#import "AccountManager.h"
#import "M_News.h"
#import "M_Comment.h"

///登录
static NSString *sub_login = @"/api/kct/login";

/// 验证码
static NSString *sub_sms = @"/api/kct/send/code";

/// 注册
static NSString *sub_register = @"/api/kct/register";

/// 文件上传
static NSString *sub_upload = @"/api/system/file/upload";

///修改用户信息
static NSString *sub_modify_user_info = @"/api/web/member/update/info";

///忘记密码
static NSString *sub_forgot_password = @"/api/kct/forget";

/// 存储登陆日志
static NSString *sub_login_log = @"/api/xcx/login/log";

///添加新闻浏览记录
static NSString *sub_log_news = @"/api/web/member/save/view";

/// 浏览记录分页列表
static NSString *sub_viewed_news = @"/api/web/member/view/v2";

/// 商圈列表
static NSString *sub_area = @"/api/web/news/area";

///商圈新闻列表
static NSString *sub_area_news = @"/api/web/news/arealist";

///点赞
static NSString *sub_like = @"/api/web/member/like";

///取消点赞
static NSString *sub_unlike = @"/api/web/member/unlike";

///点赞/收藏列表
static NSString *sub_like_list = @"/api/web/member/star/v2";

///评论列表
static NSString *sub_comments = @"/api/web/comment/list";

///添加积分
static NSString *sub_add_score = @"/api/web/member/save/score";

/// 查询会员积分
static NSString *sub_query_score = @"/api/web/member/score";

/// 获取区域
static NSString *sub_recommids = @"/api/web/news/recommids";

/// 发表评论
static NSString *sub_send_comments = @"/api/web/comment/save";

///我的评论
static NSString *sub_my_comments = @"/api/web/comment/member/list/v2";

@implementation ServiceUserNew

+ (NSURLSessionDataTask *)doLogin:(NSString *)phoneNum_ password:(NSString *)password_ success:(void (^)(id _Nonnull, NSString * _Nonnull))success_ failure:(void (^)(NSString * _Nonnull))failure_ {
    
    NSString *urlString = [base_url stringByAppendingString:sub_login];
    
    NSDictionary *dic = @{@"phone": phoneNum_,
                          @"password": password_};
    
    return [[ServiceUtils commonHTTPManager2] POST:urlString parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
            NSString *message = [responseObject objectForKey:@"message"];
            id data = [responseObject objectForKey:@"data"];
            if (code == 0) {
                success_(data,message);
            }
            else {
                failure_(message);
            }
        }
        else {
            failure_(@"网络不给力");
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

+ (NSURLSessionDataTask *)doGetPhoneCode:(NSString *)phoneNum_ success:(void (^)(id _Nonnull, NSString * _Nonnull))success_ failure:(void (^)(NSString * _Nonnull))failure_ {
    NSString *urlString = [base_url stringByAppendingString:sub_sms];
    
    NSDictionary *dic = @{@"phone": phoneNum_};
    
    return [[ServiceUtils commonHTTPManager2] POST:urlString parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
            NSString *message = [responseObject objectForKey:@"message"];
            id data = [responseObject objectForKey:@"data"];
            if (code == 0) {
                success_(data,message);
            }
            else {
                failure_(message);
            }
        }
        else {
            failure_(@"网络不给力");
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

+ (NSURLSessionDataTask *)doUpload:(NSString *)imgPath success:(void (^)(id _Nonnull, NSString * _Nonnull))success_ failure:(void (^)(NSString * _Nonnull))failure_ {
    
    NSString *urlString = [base_url stringByAppendingString:sub_upload];
    NSMutableURLRequest *request =
    [[AFHTTPRequestSerializer serializer]
        multipartFormRequestWithMethod:@"POST"
                            URLString:urlString
                            parameters:@{}
            constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
                [formData appendPartWithFileURL:[NSURL fileURLWithPath:imgPath] name:@"file" fileName:@"test1.png" mimeType:@"image/png" error:nil];
            } error:nil];
    
    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    
    AFJSONResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializer];
    responseSerializer.acceptableContentTypes = [NSSet setWithArray:@[@"text/html",@"application/json"]];
    manager.responseSerializer = responseSerializer;
    
    NSURLSessionUploadTask *task = [manager uploadTaskWithStreamedRequest:request progress:nil completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
        if(!error) {
            if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
                NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
                NSString *message = [responseObject objectForKey:@"message"];
                id data = [responseObject objectForKey:@"data"];
                if (code == 0) {
                    success_(data,message);
                }
                else {
                    failure_(message);
                }
            }
            else {
                failure_(@"网络不给力");
            }
        } else {
            if (failure_) {
                failure_(@"上传失败");
            }
        }
        
    }];
    
    [task resume];
    return task;
}

+ (NSURLSessionDataTask *)doRegister:(NSString *)phoneNum_ password:(NSString *)password_ code:(NSString *)code_ success:(void (^)(id _Nonnull, NSString * _Nonnull))success_ failure:(void (^)(NSString * _Nonnull))failure_ {
    NSString *urlString = [base_url stringByAppendingString:sub_register];
    
    NSDictionary *dic = @{@"phone": phoneNum_,
                          @"password": password_,
                          @"code": code_};
    
    return [[ServiceUtils commonHTTPManager2] POST:urlString parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
            NSString *message = [responseObject objectForKey:@"message"];
            id data = [responseObject objectForKey:@"data"];
            if (code == 0) {
                success_(data,message);
            }
            else {
                failure_(message);
            }
        }
        else {
            failure_(@"网络不给力");
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

+ (NSURLSessionDataTask *)doModifyUserInfo:(NSString *)nick_name cover:(NSString *)cover sex:(NSInteger)sex success:(void (^)(id _Nonnull, NSString * _Nonnull))success_ failure:(void (^)(NSString * _Nonnull))failure_ {
    NSString *urlString = [base_url stringByAppendingString:sub_modify_user_info];
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    if (nick_name) {
        [dic setValue:nick_name forKey:@"nick_name"];
    }
    if (cover) {
        [dic setValue:cover forKey:@"cover"];
    }
    [dic setValue:@(sex) forKey:@"sex"];
    [dic setValue:[AccountManager sharedAccountManager].f_authCode forKey:@"token"];
    
    return [[ServiceUtils commonHTTPManager2] POST:urlString parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
            NSString *message = [responseObject objectForKey:@"message"];
            id data = [responseObject objectForKey:@"data"];
            if (code == 0) {
                success_(data,message);
            }
            else {
                failure_(message);
            }
        }
        else {
            failure_(@"网络不给力");
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

+ (NSURLSessionDataTask *)doForgotPassword:(NSString *)phone new_pwd:(NSString *)new_pwd new_pwd2:(NSString *)new_pwd2 code:(NSString *)code success:(void (^)(id _Nonnull, NSString * _Nonnull))success_ failure:(void (^)(NSString * _Nonnull))failure_ {
    NSString *urlString = [base_url stringByAppendingString:sub_forgot_password];
    NSDictionary *dic = @{@"phone": phone,
                          @"new_pwd": new_pwd,
                          @"new_pwd2": new_pwd2,
                          @"code": code};
    return [[ServiceUtils commonHTTPManager2] POST:urlString parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
            NSString *message = [responseObject objectForKey:@"message"];
            id data = [responseObject objectForKey:@"data"];
            if (code == 0) {
                success_(data,message);
            }
            else {
                failure_(message);
            }
        }
        else {
            failure_(@"网络不给力");
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

+ (NSURLSessionDataTask *)doLoginLog:(NSString *)phoneNum_ location:(CLLocationCoordinate2D)location success:(void (^)(id _Nonnull, NSString * _Nonnull))success_ failure:(void (^)(NSString * _Nonnull))failure_ {
    NSDictionary *dic = @{@"token": [AccountManager sharedAccountManager].f_authCode,
                          @"source": @"看楚天",
                          @"type":@(1),
                          @"latitude":@(location.latitude),
                          @"longitude":@(location.longitude),
                          @"account":phoneNum_ };
    NSString *urlString = [base_url stringByAppendingString:sub_login_log];
    return [[ServiceUtils commonHTTPManager2] POST:urlString parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
            NSString *message = [responseObject objectForKey:@"message"];
            id data = [responseObject objectForKey:@"data"];
            if (code == 0) {
                
                id rows = [data objectForKey:@"rows"];
                NSError *error;
                NSArray *list = [MTLJSONAdapter modelsOfClass:[M_News class] fromJSONArray:rows error:&error];
                if (!list) {
                    list = @[];
                }
                
                success_(list,message);
            }
            else {
                failure_(message);
            }
        }
        else {
            failure_(@"网络不给力");
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

+ (NSURLSessionDataTask *)doLogNews:(NSString *)article_id success:(void (^)(id _Nonnull, NSString * _Nonnull))success_ failure:(void (^)(NSString * _Nonnull))failure_ {
    if ([AccountManager sharedAccountManager].f_isLogined) {
        NSDictionary *dic = @{@"token": [AccountManager sharedAccountManager].f_authCode,
                              @"article_id": article_id };
        NSString *urlString = [base_url stringByAppendingString:sub_log_news];
        return [[ServiceUtils commonHTTPManager2] POST:urlString parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
                NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
                NSString *message = [responseObject objectForKey:@"message"];
                id data = [responseObject objectForKey:@"data"];
                if (code == 0) {
                    success_(data,message);
                }
                else {
                    failure_(message);
                }
            }
            else {
                failure_(@"网络不给力");
            }
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            if (failure_) {
                failure_(@"网络不给力");
            }
        }];
    }
    return nil;
}

+ (NSURLSessionDataTask *)doGetViewedNews:(NSInteger)pageNum pageSize:(NSInteger)pageSize success:(void (^)(id _Nonnull, NSString * _Nonnull))success_ failure:(void (^)(NSString * _Nonnull))failure_ {
    NSDictionary *dic = @{@"token": [AccountManager sharedAccountManager].f_authCode,
                          @"pageNum": @(pageNum),
                          @"pageSize":@(pageSize)};
    NSString *urlString = [base_url stringByAppendingString:sub_viewed_news];
    return [[ServiceUtils commonHTTPManager2] POST:urlString parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
            NSString *message = [responseObject objectForKey:@"message"];
            id data = [responseObject objectForKey:@"data"];
            if (code == 0) {
                
                NSError *error;
                NSArray *list = [MTLJSONAdapter modelsOfClass:[M_News class] fromJSONArray:data error:&error];
                if (!list) {
                    list = @[];
                }
                
                success_(list,message);
            }
            else {
                failure_(message);
            }
        }
        else {
            failure_(@"网络不给力");
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

+ (NSURLSessionDataTask *)doGetArea:(void (^)(id _Nonnull, NSString * _Nonnull))success_ failure:(void (^)(NSString * _Nonnull))failure_ {
    NSDictionary *dic = @{};
    NSString *urlString = [base_url stringByAppendingString:sub_area];
    return [[ServiceUtils commonHTTPManager2] POST:urlString parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
            NSString *message = [responseObject objectForKey:@"message"];
            id data = [responseObject objectForKey:@"data"];
            if (code == 0) {
                success_(data,message);
            }
            else {
                failure_(message);
            }
        }
        else {
            failure_(@"网络不给力");
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

+ (NSURLSessionDataTask *)doGetAreaNews:(NSString *)areaId pageNum:(NSInteger)pageNum pageSize:(NSInteger)pageSize success:(void (^)(id _Nonnull, NSString * _Nonnull))success_ failure:(void (^)(NSString * _Nonnull))failure_ {
    NSDictionary *dic = @{@"area_id": areaId,
                          @"pageNum": @(pageNum),
                          @"pageSize":@(pageSize)};
    NSString *urlString = [base_url stringByAppendingString:sub_area_news];
    return [[ServiceUtils commonHTTPManager2] POST:urlString parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
            NSString *message = [responseObject objectForKey:@"message"];
            id data = [responseObject objectForKey:@"data"];
            if (code == 0) {
                
                id rows = [data objectForKey:@"rows"];
                NSError *error;
                NSArray *list = [MTLJSONAdapter modelsOfClass:[M_News class] fromJSONArray:rows error:&error];
                if (!list) {
                    list = @[];
                }
                
                success_(list,message);
            }
            else {
                failure_(message);
            }
        }
        else {
            failure_(@"网络不给力");
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

+ (NSURLSessionDataTask *)doLike:(NSString *)article_id success:(void (^)(id _Nonnull, NSString * _Nonnull))success_ failure:(void (^)(NSString * _Nonnull))failure_ {
    NSDictionary *dic = @{@"token": [AccountManager sharedAccountManager].f_authCode,
                           @"article_id": article_id};
     NSString *urlString = [base_url stringByAppendingString:sub_like];
     return [[ServiceUtils commonHTTPManager2] POST:urlString parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
     } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
         if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
             NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
             NSString *message = [responseObject objectForKey:@"message"];
             id data = [responseObject objectForKey:@"data"];
             if (code == 0) {
                 success_(data,message);
             }
             else {
                 failure_(message);
             }
         }
         else {
             failure_(@"网络不给力");
         }
     } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
         if (failure_) {
             failure_(@"网络不给力");
         }
     }];
}

+ (NSURLSessionDataTask *)doUnLike:(NSString *)article_id success:(void (^)(id _Nonnull, NSString * _Nonnull))success_ failure:(void (^)(NSString * _Nonnull))failure_ {
    NSDictionary *dic = @{@"token": [AccountManager sharedAccountManager].f_authCode,
                           @"article_id": article_id};
     NSString *urlString = [base_url stringByAppendingString:sub_unlike];
     return [[ServiceUtils commonHTTPManager2] POST:urlString parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
     } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
         if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
             NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
             NSString *message = [responseObject objectForKey:@"message"];
             id data = [responseObject objectForKey:@"data"];
             if (code == 0) {
                 success_(data,message);
             }
             else {
                 failure_(message);
             }
         }
         else {
             failure_(@"网络不给力");
         }
     } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
         if (failure_) {
             failure_(@"网络不给力");
         }
     }];
}

+ (NSURLSessionDataTask *)doGetLikeList:(NSInteger)pageNum pageSize:(NSInteger)pageSize success:(void (^)(id _Nonnull, NSString * _Nonnull))success_ failure:(void (^)(NSString * _Nonnull))failure_ {
    NSDictionary *dic = @{@"token": [AccountManager sharedAccountManager].f_authCode,
                          @"pageNum": @(pageNum),
                          @"pageSize":@(pageSize)};
    NSString *urlString = [base_url stringByAppendingString:sub_like_list];
    return [[ServiceUtils commonHTTPManager2] POST:urlString parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
            NSString *message = [responseObject objectForKey:@"message"];
            id data = [responseObject objectForKey:@"data"];
            if (code == 0) {
                
                NSError *error;
                NSArray *list = [MTLJSONAdapter modelsOfClass:[M_News class] fromJSONArray:data error:&error];
                if (!list) {
                    list = @[];
                }
                
                success_(list,message);
            }
            else {
                failure_(message);
            }
        }
        else {
            failure_(@"网络不给力");
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

+ (NSURLSessionDataTask *)doGetComments:(NSString *)article_id success:(void (^)(id _Nonnull, NSString * _Nonnull))success_ failure:(void (^)(NSString * _Nonnull))failure_ {
    NSDictionary *dic = @{@"article_id": article_id};
     NSString *urlString = [base_url stringByAppendingString:sub_comments];
     return [[ServiceUtils commonHTTPManager2] POST:urlString parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
     } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
         if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
             NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
             NSString *message = [responseObject objectForKey:@"message"];
             id data = [responseObject objectForKey:@"data"];
             if (code == 0) {
                 NSError *error;
                 NSArray *list = [MTLJSONAdapter modelsOfClass:[M_Comment class] fromJSONArray:data error:&error];
                 if (!list) {
                     list = @[];
                 }
                 
                 success_(list,message);
             }
             else {
                 failure_(message);
             }
         }
         else {
             failure_(@"网络不给力");
         }
     } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
         if (failure_) {
             failure_(@"网络不给力");
         }
     }];
}

+ (NSURLSessionDataTask *)doAddScore:(AddScoreType)type success:(void (^)(id _Nonnull, NSString * _Nonnull))success_ failure:(void (^)(NSString * _Nonnull))failure_ {
    
    if (![AccountManager sharedAccountManager].f_isLogined) {
        return nil;
    }
    
    NSString *code = @"";
    switch (type) {
        case AddScoreType_Login:
            code = @"login";
            break;
        case AddScoreType_News:
            code = @"news";
            break;
        case AddScoreType_clickadv:
            code = @"clickadv";
            break;
        case AddScoreType_clickrmt:
            code = @"clickrmt";
            break;
        case AddScoreType_baoliao:
            code = @"baoliao";
            break;
        case AddScoreType_share:
            code = @"share";
            break;
        case AddScoreType_comment:
            code = @"comment";
            break;
        case AddScoreType_star:
            code = @"star";
            break;
        default:
            break;
    }
    
    if ([code length] == 0) {
        return nil;
    }
    
    NSDictionary *dic = @{@"token": [AccountManager sharedAccountManager].f_authCode,
                          @"code": code};
     NSString *urlString = [base_url stringByAppendingString:sub_add_score];
     return [[ServiceUtils commonHTTPManager2] POST:urlString parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
     } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
         if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
             NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
             NSString *message = [responseObject objectForKey:@"message"];
             id data = [responseObject objectForKey:@"data"];
             if (code == 0) {
                 success_(data,message);
             }
             else {
                 failure_(message);
             }
         }
         else {
             failure_(@"网络不给力");
         }
     } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
         if (failure_) {
             failure_(@"网络不给力");
         }
     }];
    
}

+ (NSURLSessionDataTask *)doQueryScore:(void (^)(id _Nonnull, NSString * _Nonnull))success_ failure:(void (^)(NSString * _Nonnull))failure_ {
    NSDictionary *dic = @{@"token": [AccountManager sharedAccountManager].f_authCode};
     NSString *urlString = [base_url stringByAppendingString:sub_query_score];
     return [[ServiceUtils commonHTTPManager2] POST:urlString parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
     } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
         if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
             NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
             NSString *message = [responseObject objectForKey:@"message"];
             id data = [responseObject objectForKey:@"data"];
             if (code == 0) {
                 success_(data,message);
             }
             else {
                 failure_(message);
             }
         }
         else {
             failure_(@"网络不给力");
         }
     } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
         if (failure_) {
             failure_(@"网络不给力");
         }
     }];
}

+ (NSURLSessionDataTask *)doGetRecommids:(CLLocationCoordinate2D)location success:(void (^)(id _Nonnull, NSString * _Nonnull))success_ failure:(void (^)(NSString * _Nonnull))failure_ {
    NSDictionary *dic = @{@"latitude": @(location.latitude),@"longitude":@(location.longitude)};
     NSString *urlString = [base_url stringByAppendingString:sub_recommids];
     return [[ServiceUtils commonHTTPManager2] POST:urlString parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
     } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
         if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
             NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
             NSString *message = [responseObject objectForKey:@"message"];
             id data = [responseObject objectForKey:@"data"];
             if (code == 0) {
                 success_(data,message);
             }
             else {
                 failure_(message);
             }
         }
         else {
             failure_(@"网络不给力");
         }
     } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
         if (failure_) {
             failure_(@"网络不给力");
         }
     }];
}

+ (NSURLSessionDataTask *)doSendComment:(NSString *)article_id content:(NSString *)content pid:(NSString *)pid to_id:(NSString *)to_id success:(void (^)(id _Nonnull, NSString * _Nonnull))success_ failure:(void (^)(NSString * _Nonnull))failure_ {
    NSString *urlString = [base_url stringByAppendingString:sub_send_comments];
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    if (pid) {
        [dic setValue:pid forKey:@"pid"];
    }
    if (to_id) {
        [dic setValue:to_id forKey:@"to_id"];
    }
    
    [dic setValue:content forKey:@"content"];
    [dic setValue:article_id forKey:@"article_id"];
    [dic setValue:[AccountManager sharedAccountManager].f_authCode forKey:@"token"];
    
    return [[ServiceUtils commonHTTPManager2] POST:urlString parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
            NSString *message = [responseObject objectForKey:@"message"];
            id data = [responseObject objectForKey:@"data"];
            if (code == 0) {
                success_(data,message);
            }
            else {
                failure_(message);
            }
        }
        else {
            failure_(@"网络不给力");
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

+ (NSURLSessionDataTask *)doGetMyComments:(NSInteger)pageNum pageSize:(NSInteger)pageSize success:(void (^)(id, NSString *))success_ failure:(void (^)(NSString *))failure_ {
    NSDictionary *dic = @{@"token": [AccountManager sharedAccountManager].f_authCode,
                          @"pageNum": @(pageNum),
                          @"pageSize":@(pageSize)};
    NSString *urlString = [base_url stringByAppendingString:sub_my_comments];
    return [[ServiceUtils commonHTTPManager2] POST:urlString parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
            NSString *message = [responseObject objectForKey:@"message"];
            id data = [responseObject objectForKey:@"data"];
            if (code == 0) {
                
                NSError *error;
                NSArray *list = [MTLJSONAdapter modelsOfClass:[M_News class] fromJSONArray:data error:&error];
                if (!list) {
                    list = @[];
                }
                
                success_(list,message);
            }
            else {
                failure_(message);
            }
        }
        else {
            failure_(@"网络不给力");
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}
@end
